package com.otherTest.date;

import org.junit.Test;

import java.math.BigDecimal;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Conceit
 * @version 1.0, 2016/12/5
 */
public class TestTime {
    @Test
    public void test() {
//        Date startDate=null;
//        Date endDate=null;
//
//
//        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd 00:00:00");
//        Date date=new Date();
//        Date dateTest=new Date();
//        sdf.format(dateTest);
//        try {
//            date =sdf.parse(sdf.format(date));
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//
//        System.out.println(date);//date-Mon Dec 05 16:02:59 CST 2016
//        System.out.println(sdf.format(date));//string-2016-12-05 00:00:00
//        System.out.println(sdf.format(date));//date-2016-12-05 00:00:00
//
//        System.out.println("---------------------------------------------------------");
//        startDate=date;
//        System.out.println(startDate.getTime());
//        System.out.println(startDate.getTime() - 12 * 60 * 60 * 1000);
//
//        //当前系统时间毫秒数减去十二小时的毫秒数
//        endDate = new Date(startDate.getTime() - 12 * 60 * 60 * 1000);//Sun Dec 04 12:00:00 CST 2016
//        System.out.println(endDate);
//        int i = 1;
//        if (1 > 0) {
//            System.out.println("大于1");
//        }
//        System.out.println("还是执行");
        Date startTime = null;
        Date endTime = null;

        SimpleDateFormat cutter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
        Date date = new Date();
        String strTime=null;
        strTime=cutter.format(date);
        Date testDate=new Date();
        try {
            cutter.parse(strTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println(date);
        System.out.println(strTime);//2016-12-23 00:00:00
        try {
            System.out.println(testDate=cutter.parse(strTime));//Fri Dec 23 00:00:00 CST 2016
        } catch (ParseException e) {
            e.printStackTrace();
        }

        //endTime = new Date(startTime.getTime() - 3 * 60 * 60 * 1000);
    }
    @Test
    public void test2(){
        for(int i=0;i<=15;i+=3){
            Date now = new Date();
            Date endTime = new Date(now.getTime()-i * 60 *1000);
            Date startTime = new Date(now.getTime() - (i+3) * 60 *1000);
            System.out.println("startTime"+startTime+System.lineSeparator()+"endTime"+endTime);
        }
    }

     /**
       * 毫秒转换为 秒，分钟，小时，天

      */
    @Test
    public void test3(){
     long millisecond=25000;

        if(millisecond!=0){
            //秒
            double second=millisecond/1000;
            //分钟
            double minute=second/60;
            //小时
            double hour=minute/60;
            //天
            double day=hour/24;
            BigDecimal bigDecimalDay=new BigDecimal(day).setScale(8, BigDecimal.ROUND_HALF_UP);

            System.out.println("     秒："+second+"     分钟："+minute+"     小时："+hour+"      天："+day+"    非科学计数法天："+bigDecimalDay);
        }

    }



}
